home *** CD-ROM | disk | FTP | other *** search
/ HAKERIS 11 / HAKERIS 11.ISO / linux / system / LinuxConsole 0.4 / linuxconsole0.4install-en.iso / guile0.4.lcm / share / guile / slib / pscheme.init < prev    next >
Encoding:
Text File  |  2004-01-06  |  5.9 KB  |  205 lines

  1. ;;; "pscheme.init" -*-scheme-*-
  2. ;;; SLIB init file for Pocket Scheme
  3. ;;; SLIB orig Author: Aubrey Jaffer (jaffer@ai.mit.edu)
  4. ;;; Author: Ben Goetter <goetter@angrygraycat.com>
  5. ;;; Initial work for 0.2.3 by Robert Goldman (goldman@htc.honeywell.com)
  6. ;;;
  7. ;;; This code is in the public domain.
  8.  
  9. ; best fit for Windows CE?
  10. (define (software-type) 'MS-DOS)
  11.  
  12. (define (scheme-implementation-type) 'PocketScheme)
  13. (define (scheme-implementation-version) "0.3.6")
  14.  
  15. (define in-vicinity string-append)
  16.  
  17. (define (implementation-vicinity)
  18.   "\\Program Files\\Pocket Scheme\\")
  19.  
  20. (define (library-vicinity)
  21.   (in-vicinity (implementation-vicinity) "slib\\"))
  22.  
  23. (define (home-vicinity)
  24.   "\\My Documents\\")
  25.  
  26. (define *features*
  27.   '(source
  28.     rev4-report
  29.     ieee-p1178
  30.     rev4-optional-procedures
  31.     multiarg/and-
  32.     multiarg-apply
  33.     with-file
  34.     char-ready?
  35.     defmacro
  36.     delay
  37.     eval
  38.     dynamic-wind
  39.     full-continuation
  40.     ;;trace                ; Comment out for SLIB TRACE macros
  41.     system
  42.     string-port
  43.     ))
  44.  
  45. ;;; (OUTPUT-PORT-WIDTH <port>)
  46. (define (output-port-width . arg) 79)
  47.  
  48. ;;; (OUTPUT-PORT-HEIGHT <port>)
  49. (define (output-port-height . arg) 12)
  50.  
  51. ;;; (TMPNAM) makes a temporary file name.
  52. (define tmpnam (let ((cntr 100))
  53.          (lambda () (set! cntr (+ 1 cntr))
  54.              (string-append "slib_" (number->string cntr)))))
  55.  
  56. ;;; (FILE-EXISTS? <string>)
  57. (define (file-exists? f) 
  58.   (let ((file #f))
  59.     (with-handlers (((lambda (x) #t) (lambda (x) #f)))
  60.            (set! file (open-input-file f))
  61.            (close-input-port file)
  62.            #t)))
  63.  
  64. ;; pscheme: current-error-port, delete-file, force-output already defined
  65.  
  66. ;;; CHAR-CODE-LIMIT is one greater than the largest integer which can
  67. ;;; be returned by CHAR->INTEGER.
  68. ;(define char-code-limit
  69. ; (with-handlers (
  70. ;  ((lambda (x) #t) (lambda (x) 256))
  71. ;                )
  72. ;  (integer->char 65535)
  73. ;  65536))
  74. ;;; Currently there are only three clients of this symbol. 
  75. ;;; Following observations relate to PScheme 0.3.5, JACAL 1a9, SLIB 2c5.
  76. ;;; JACAL: crashes when set to 65536.
  77. ;;; make-crc: extremely inefficient when set to 65536, spending forever in init
  78. ;;; precedence-parse: ignores any setting in excess of 256
  79. ;;; So we patch it to 256.
  80. (define char-code-limit 256)
  81.  
  82. ;;; MOST-POSITIVE-FIXNUM is used in modular.scm
  83. ;;; This is the most positive immediate-value fixnum in PScheme.
  84. ;;; The secondary representation extends fixnum values to 0xffffffff.
  85. (define most-positive-fixnum #x07FFFFFF)
  86.  
  87. ;;; Return argument
  88. (define (identity x) x)
  89.  
  90. ;;; SLIB:EVAL is single argument eval using the top-level (user) environment.
  91. (define slib:eval eval)
  92.  
  93. ;;; If your implementation provides R4RS macros:
  94. ;(define macro:eval slib:eval)
  95. ;(define macro:load load)
  96.  
  97. (define gentemp
  98.   (let ((*gensym-counter* -1))
  99.     (lambda ()
  100.       (set! *gensym-counter* (+ *gensym-counter* 1))
  101.       (string->symbol
  102.        (string-append "slib:G" (number->string *gensym-counter*))))))
  103.  
  104. (define base:eval slib:eval)
  105. (define defmacro:eval slib:eval)
  106.  
  107. (define (slib:eval-load <pathname> evl)
  108.   (if (not (file-exists? <pathname>))
  109.       (set! <pathname> (string-append <pathname> (scheme-file-suffix))))
  110.   (call-with-input-file <pathname>
  111.     (lambda (port)
  112.       (let ((old-load-pathname *load-pathname*))
  113.     (set! *load-pathname* <pathname>)
  114.     (do ((o (read port) (read port)))
  115.         ((eof-object? o))
  116.       (evl o))
  117.     (set! *load-pathname* old-load-pathname)))))
  118.  
  119. (define (defmacro:load <pathname>)
  120.   (slib:eval-load <pathname> defmacro:eval))
  121.  
  122. (define slib:warn
  123.   (lambda args
  124.     (let ((cep (current-error-port)))
  125.       (if (provided? 'trace) (print-call-stack cep))
  126.       (display "Warn: " cep)
  127.       (for-each (lambda (x) (display x cep)) args))))
  128.  
  129. ;;; Define an error procedure for the library
  130. (define (slib:error . k)
  131.   (if (provided? 'trace) (print-call-stack (current-error-port)))
  132.   (error 
  133.    (cond
  134.     ((= (length k) 0) '())
  135.     ((= (length k) 1) (car k))
  136.     ((provided? 'string-port)
  137.      (call-with-output-string
  138.       (lambda (out)
  139.     (let ((add-space #f))
  140.       (map
  141.        (lambda (arg)
  142.          (if add-space (write-char #\space out) (set! add-space #t))
  143.          (display arg out))
  144.        k)))))
  145.     (else (car k)))))
  146.  
  147. ;;; For the benefit of slib:error above, as announced by feature string-port
  148. (define (call-with-output-string t)
  149.   (let* ((p (open-output-string))
  150.      (r (t p))
  151.      (s (get-output-string p)))
  152.     (close-output-port p)
  153.     s))
  154.  
  155. (define (call-with-input-string s t)
  156.   (let* ((p (open-input-string s))
  157.      (r (t p)))
  158.     (close-input-port p)
  159.     r))
  160.  
  161. ;;; define these as appropriate for your system.
  162. (define slib:tab (integer->char 9))
  163. (define slib:form-feed (integer->char 12))
  164.  
  165. ;;; Support for older versions of Scheme.  Not enough code for its own file.
  166. (define (last-pair l) (if (pair? (cdr l)) (last-pair (cdr l)) l))
  167. (define t #t)
  168. (define nil #f)
  169.  
  170. ;;; Define these if your implementation's syntax can support it and if
  171. ;;; they are not already defined.
  172.  
  173. (define (1+ n) (+ n 1))
  174. (define (-1+ n) (+ n -1))
  175. (define 1- -1+)
  176.  
  177. ;;; Define SLIB:EXIT to be the implementation procedure to exit or
  178. ;;; return if exitting not supported.
  179. (define slib:exit exit)
  180.  
  181. ;;; Here for backward compatability
  182. (define (scheme-file-suffix) ".scm")
  183.  
  184. ;;; (SLIB:LOAD-SOURCE "foo") should load "foo.scm" or with whatever
  185. ;;; suffix all the module files in SLIB have.  See feature 'SOURCE.
  186.  
  187. (define (slib:load-source f)
  188.   (if (not (file-exists? f))
  189.       (set! f (string-append f (scheme-file-suffix))))
  190.   (load f))
  191.  
  192. ;;; (SLIB:LOAD-COMPILED "foo") should load the file that was produced
  193. ;;; by compiling "foo.scm" if this implementation can compile files.
  194. ;;; See feature 'COMPILED.
  195.  
  196. (define slib:load-compiled load)
  197.  
  198. ;;; At this point SLIB:LOAD must be able to load SLIB files.
  199.  
  200. (define slib:load slib:load-source)
  201.  
  202. ;;; Hold onto pscheme native version
  203. (define pscheme:require require)
  204. (slib:load (in-vicinity (library-vicinity) "require"))
  205.